using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Microsoft.PowerShell.CmdletManagement
{
    public partial class FreeTextExtendedTextBlock : System.Windows.Controls.UserControl
    {
        public FreeTextExtendedTextBlock()
        {
            InitializeComponent();

            FreeText.Background = SystemColors.ControlBrush;
            FreeText.IsReadOnly = true;
        }

        public string Label
        {
            get { return (string)GetValue(LabelProperty); }
            set { SetValue(LabelProperty, value); }
        }
        public static readonly DependencyProperty LabelProperty =
            DependencyProperty.Register("Label", typeof(string), typeof(FreeTextExtendedTextBlock));
        
        public string Value
        {
            get { return (string)GetValue(ValueProperty); }
            set { SetValue(ValueProperty, value); }
        }
        public static readonly DependencyProperty ValueProperty =
            DependencyProperty.Register("Value", typeof(string), typeof(FreeTextExtendedTextBlock));

        public string HelpText
        {
            get { return (string)GetValue(HelpTextProperty); }
            set { SetValue(HelpTextProperty, value); }
        }
        public static readonly DependencyProperty HelpTextProperty =
            DependencyProperty.Register("HelpText", typeof(string), typeof(FreeTextExtendedTextBlock));

        public int MinLines
        {
            get { return (int)GetValue(MinLinesProperty); }
            set { SetValue(MinLinesProperty, value); }
        }
        public static readonly DependencyProperty MinLinesProperty =
            DependencyProperty.Register("MinLines", typeof(int), typeof(FreeTextExtendedTextBlock),
            new PropertyMetadata(3));

        public string TextFontFamily
        {
            get { return (string)GetValue(TextFontFamilyProperty); }
            set { SetValue(TextFontFamilyProperty, value); }
        }
        public static readonly DependencyProperty TextFontFamilyProperty =
            DependencyProperty.Register("TextFontFamily", typeof(string), typeof(FreeTextExtendedTextBlock));

        public bool IsReadOnly
        {
            get { return (bool)GetValue(IsReadOnlyProperty); }
            set { SetValue(IsReadOnlyProperty, value); }
        }
        public static readonly DependencyProperty IsReadOnlyProperty =
            DependencyProperty.Register("IsReadOnly", typeof(bool), typeof(FreeTextExtendedTextBlock),
            new FrameworkPropertyMetadata(true, new PropertyChangedCallback(OnIsReadOnlyChanged)));

        public int TextFontSize
        {
            get { return (int)GetValue(TextFontSizeProperty); }
            set { SetValue(TextFontSizeProperty, value); }
        }

        private static void OnIsReadOnlyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            FreeTextExtendedTextBlock textBlock = d as FreeTextExtendedTextBlock;

            if (((bool)e.NewValue) == true)
            {
                textBlock.FreeText.Background = SystemColors.ControlBrush;
                textBlock.FreeText.IsReadOnly = true;
            }
            else
            {
                textBlock.FreeText.Background = SystemColors.WindowBrush;
                textBlock.FreeText.IsReadOnly = false;
            }
        }

        public static readonly DependencyProperty TextFontSizeProperty =
            DependencyProperty.Register("TextFontSize", typeof(int), typeof(FreeTextExtendedTextBlock));
    }
}